package com.uphone.kingmall.activity.personal;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.china.zhuoyue.R;
import com.google.zxing.WriterException;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.utils.ConstansUtils;
import com.uphone.kingmall.utils.DensityUtil;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.QRCodeUtils;
import com.uphone.kingmall.utils.SharedPreferencesHelper;
import com.uphone.kingmall.utils.intent.IntentData;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 王雨
 *     e-mail :
 *     time   : 2018/07/31
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class InviteCodeActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.iv_invite_code)
    ImageView ivInviteCode;
    @BindView(R.id.tv_invite_code)
    TextView tvInviteCode;
    @BindView(R.id.tv_copy)
    TextView tvCopy;
    @BindView(R.id.activity_invite)
    LinearLayout activityInvite;
    @IntentData
    private String url = "";

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_invite_code;
    }

    @Override
    public void initView() {
        setStatusBar();
        if (!TextUtils.isEmpty(SharedPreferencesHelper.getUserInviteCode())) {
            tvInviteCode.setText("推荐邀请码: " + SharedPreferencesHelper.getUserInviteCode());
        }
    }

    @Override
    public void initData() {
 /*
        绘制二维码
         */
        if (TextUtils.isEmpty(url))
            url = ConstansUtils.QRCodeUserInvite + SharedPreferencesHelper.getUserInviteCode();
        try {
            Bitmap bitmap = QRCodeUtils.createQRCode
                    (url, DensityUtil.dip2px(InviteCodeActivity.this, 260));
            ivInviteCode.setImageBitmap(bitmap);
        } catch (WriterException e) {
            e.printStackTrace();
        }
    }


    @OnClick({R.id.iv_back, R.id.tv_copy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
            case R.id.tv_copy://复制
//                CopyUtil.copy(this, SharedPreferencesHelper.getUserInviteCode() + "");
//                ToastUtils.showShortToast(this, "复制成功 " + SharedPreferencesHelper.getUserInviteCode());

                showSharePop(activityInvite, MyUrl.h5AppDownload, "邀请好友",
                        "这个商城不错哦，进来就送3个月会员", "");
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
